﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for ExpediaHotelBookingDB
/// </summary>
/// 
namespace CE.Expedia
{
    public class ExpediaHotelBookingDB
    {
        public ExpediaHotelBookingDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ExpediaHotelBookingInfo expediahotelbooking)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocExpediaHotelBookingInsertSingleItem";

            SortedList _sPara = new SortedList();
            #region Parameter

            _sPara.Add("@HotelSearchId", expediahotelbooking.HotelSearchID);
            _sPara.Add("@Email", expediahotelbooking.Email);
            _sPara.Add("@FirstName", expediahotelbooking.FirstName);
            _sPara.Add("@LastName", expediahotelbooking.LastName);
            _sPara.Add("@CustomerSessionId", expediahotelbooking.CustomerSessionId);
            _sPara.Add("@ArrivalDate", expediahotelbooking.ArrivalDate);
            _sPara.Add("@DepartureDate", expediahotelbooking.DepartureDate);
            _sPara.Add("@NoOfRooms", expediahotelbooking.NoOfRooms);
            _sPara.Add("@NoOfAdults", expediahotelbooking.NoOfAdults);
            _sPara.Add("@NoOfChild", expediahotelbooking.NoOfChild);
            _sPara.Add("@HotelId", expediahotelbooking.HotelID);
            _sPara.Add("@HotelName", expediahotelbooking.HotelName);
            _sPara.Add("@RateKey", expediahotelbooking.RateKey);
            _sPara.Add("@RoomTypeCode", expediahotelbooking.RoomTypeCode);
            _sPara.Add("@RateCode", expediahotelbooking.RateCode);
            _sPara.Add("@SupplierType", expediahotelbooking.SupplierType);
            _sPara.Add("@ChargeableRate", expediahotelbooking.ChargeableRate);
            _sPara.Add("@Address", expediahotelbooking.Address);
            _sPara.Add("@CountryCode", expediahotelbooking.CountryCode);
            _sPara.Add("@PostalCode", expediahotelbooking.PostalCode);
            _sPara.Add("@Info1", expediahotelbooking.Info1);


            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 Confirm(Int64 HotelBookingId, string ItineraryNum, string ConfirmationNum, string returnstatusmessage)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocExpediaHotelBookingConfirmBooking";

            SortedList _sPara = new SortedList();

            _sPara.Add("@HotelBookingId", HotelBookingId);
            _sPara.Add("@ItineraryNum", ItineraryNum);
            _sPara.Add("@ConfirmationNum", ConfirmationNum);
            _sPara.Add("@ExpReturnMessage", returnstatusmessage);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateErrMessage(Int64 HotelBookingId, string returnstatusmessage)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocExpediaHotelBookingUpdateReturnMessage";

            SortedList _sPara = new SortedList();

            _sPara.Add("@HotelBookingId", HotelBookingId);
            _sPara.Add("@ExpReturnMessage", returnstatusmessage);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 CancelBooking(Int64 HotelBookingId, string cancellationNumber)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocExpediaHotelBookingCancel";

            SortedList _sPara = new SortedList();

            _sPara.Add("@HotelBookingId", HotelBookingId);
            _sPara.Add("@CancellationNumber", cancellationNumber);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public DataTable GetBookingDetails(Int64 HotelBookingId)
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("HotelDetails");
            string _spName = "sprocExpediaHotelBookingSelectSingleItem";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HotelBookingId", HotelBookingId);
            #endregion

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);
            return _dtResult;
        }

        public bool GetBookingDetailsBySearchId(Int64 HotelSearchId)
        {
            bool isExisting = false;
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("HotelDetails");
            string _spName = "sprocExpediaHotelBookingSelectSingleItemBySearchId";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HotelSearchId", HotelSearchId);
            #endregion

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);

            if (_dtResult.Rows.Count > 0)
                isExisting = true;

            return isExisting;
        }


        public DataTable GetBookingDetailsByEmailItinerary(string Email, string Itinerary)
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("HotelDetails");
            string _spName = "sprocExpediaHotelBookingSelectItemByEmailItinerary";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@Email", Email);
            _sPara.Add("@Itinerary", Itinerary);
            #endregion

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);
            return _dtResult;
        }
    }
}